package com.example.service;


import com.example.mapper.UserMapper;
import com.example.pojo.User;
import com.example.util.RespPageEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UtilpageService {
@Resource
private UserMapper userMapper;

    @Transactional
    public RespPageEntity getAllUserByPage(Integer page, Integer size) {
        RespPageEntity pageEntity = new RespPageEntity();
        // 默认从0开始
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        // 获取当前也用户信息
        List<User> users = userMapper.getAllbypage(page, size);
        pageEntity.setData(users);
        // 获取当前用户总量
        Long total = userMapper.getTotal();
        pageEntity.setTotal(total);
        return pageEntity;
    }
}
